﻿<template>
    <div style="height:100%;">
        <Row>
            <Col span="24" class="col-margin">
            <!--根据需求删除不不要查询条件-->
            动作名称：
            <Input v-model="searchModel.ActionName" placeholder="请输入查询的动作名称值..." style="width: 150px"></Input>
            操作地址：
            <Input v-model="searchModel.ActionCode" placeholder="请输入查询的操作地址值..." style="width: 150px"></Input>
            操作人：
            <Input v-model="searchModel.Account" placeholder="请输入查询的操作人值..." style="width: 150px"></Input>
            日志时间：
            <Input v-model="searchModel.LogsTime" placeholder="请输入查询的日志时间值..." style="width: 150px"></Input>
            IP地址：
            <Input v-model="searchModel.IpAddress" placeholder="请输入查询的IP地址值..." style="width: 150px"></Input>
            <Button icon="ios-search" type="ghost" @click="getPageData()">查询</Button>
            </Col>
        </Row>
        <Row>
            <Col span="24" class="col-margin">
            <Button icon="plus" type="primary" @click="showType = true">新增</Button>
            <Button icon="android-done-all" type="primary" @click="multiSelect">批量删除</Button>
            </Col>
        </Row>
        <Row>
            <Col span="24" class="col-margin">
            <!--<div id="griddiv" style="overflow-y:auto" v-bind:style="{ height: clientHeight + 'px' }">
                    <table class="gridtable">
                        <thead>
                            <tr>
                                <th>动作名称</th>
                                <th>操作地址</th>
                                <th>操作人</th>
                                <th>日志时间</th>
                                <th>IP地址</th>
                                <th class="ivu-table-column-center">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr v-for="item in datas.rows">
                                <td style="text-align: center;width:17%">{{item.ActionName}}</td>
                                <td style="text-align: center;width:17%">{{item.ActionCode}}</td>
                                <td style="text-align: center;width:17%">{{item.Account}}</td>
                                <td style="text-align: center;width:17%">{{item.LogsTime}}</td>
                                <td style="text-align: center;width:17%">{{item.IpAddress}}</td>
                                <td style="text-align: center;width:15%">
                                    <i-button type="ghost" size="small" icon="ios-compose" style="color:#3399FF" @click="editInfo(item.Id)">
                                        <span style="color:#000;">编辑</span>
                                    </i-button>
                                    <i-button type="ghost" size="small" icon="ios-trash-outline" style="color:#FF0000" @click="delInfo(item.Id)">
                                        <span style="color:#000;">删除</span>
                                    </i-button>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>-->
            <Table size="small" @on-select="selectSingel" @on-select-all="selectAll" :height="clientHeight" border :context="ctx" :columns="columnsList" :data="datas.rows" no-data-text='暂无数据...'></Table>
            </Col>
        </Row>
        <Row>
            <Col span="24">
            <Page class="page-style" :total="datas.total" placement="top" @on-change="getPageNumber" :page-size="searchModel.PageSize" :page-size-opts='pageSizeOpts' show-sizer @on-page-size-change="getPageSize" show-total show-elevator></Page>
            </Col>
        </Row>
        <Modal v-model="showType" :mask-closable="false" :closable="false">
            <p slot="header" class="title">
                <Icon type="ios-paper" size="20"></Icon>
                <span style="font-size: 20px">信息编辑</span>
            </p>
            <p slot="close">
                <Icon type="close-circled" color="red" size=25></Icon>
            </p>
            <div slot="footer">
                <Button type="primary" @click="save('dataModel')">提交</Button>
                <Button type="ghost" @click="cancel('dataModel')" style="margin-left: 8px">取消</Button>
            </div>
            <Form ref="dataModel" :model="dataModel" :rules="ruleValidate" :label-width="100">
                <Form-item style="display:none;" prop="Id">
                    <Input v-model="dataModel.Id"></Input>
                </Form-item>
                <Form-item label="动作名称" prop="ActionName">
                    <Input v-model="dataModel.ActionName" placeholder="请输入动作名称"></Input>
                </Form-item>
                <Form-item label="操作地址" prop="ActionCode">
                    <Input v-model="dataModel.ActionCode" placeholder="请输入操作地址"></Input>
                </Form-item>
                <Form-item label="操作人" prop="Account">
                    <Input v-model="dataModel.Account" placeholder="请输入操作人"></Input>
                </Form-item>
                <Form-item label="日志时间" prop="LogsTime">
                    <Input v-model="dataModel.LogsTime" placeholder="请输入日志时间"></Input>
                </Form-item>
                <Form-item label="IP地址" prop="IpAddress">
                    <Input v-model="dataModel.IpAddress" placeholder="请输入IP地址"></Input>
                </Form-item>
            </Form>
        </Modal>
    </div>
</template>
<script>
export default {
    data() {
        return {
            showType: false,//编辑框弹出状态
            ruleValidate: {//验证模型
                ActionName: [{ required: true, message: '动作名称不能为空', trigger: 'blur' }],
                ActionCode: [{ required: true, message: '操作地址不能为空', trigger: 'blur' }],
                Account: [{ required: true, message: '操作人不能为空', trigger: 'blur' }],
                LogsTime: [{ required: true, message: '日志时间不能为空', trigger: 'blur' }],
                IpAddress: [{ required: true, message: 'IP地址不能为空', trigger: 'blur' }],
            },
            dataModel: {//编辑模型
                Id: 0,
                ActionName: '',
                ActionCode: '',
                Account: '',
                LogsTime: '',
                IpAddress: '',
            },
            clientHeight: window.innerHeight - 265,//表格默认高度
            //查询模型：根据需求删除不不要查询条件
            searchModel: {
                Id: '',
                ActionName: '',
                ActionCode: '',
                Account: '',
                LogsTime: '',
                IpAddress: '',
                PageNumber: 1, PageSize: 20
            },
            pageSizeOpts: [20, 40, 50],//默认分页最大设置
            datas: {},//table数据对象
            dataIds: [],
            ctx: this,//table数据上下文
            columnsList: [//表头对象
                //{ type: 'selection', width: 60, align: 'center' },//多选设置
                { title: "动作名称", key: "ActionName" },
                { title: "操作地址", key: "ActionCode" },
                { title: "操作人", key: "Account" },
                { title: "日志时间", key: "LogsTime" },
                { title: "IP地址", key: "IpAddress" },
                // {
                //     title: "操作", key: "Id", width: 200, align: 'center', render(row, column, index) {
                //         return `
                //          <i-button type="ghost" size="small" icon="ios-compose" style="color:#3399FF" @click="editInfo('${row.Id}')"><span style="color:#000;">编辑</span></i-button>
                // 		 <i-button type="ghost" size="small" icon="ios-trash-outline" style="color:#FF0000" @click="delInfo('${row.Id}')"><span style="color:#000;">删除</span></i-button>
                // 		`;
                //     }
                // }
            ]
        }
    },
    mounted() {
        //table高度计算方法
        const that = this;
        window.onresize = () => {
            return (() => {
                that.clientHeight = window.innerHeight - 265;
            })()
        };
    },
    methods: {
        //获取当前页码
        getPageNumber(pageIndex) {
            this.searchModel.PageNumber = pageIndex;
            this.getPageData();
        },
        //获取当前分页大小
        getPageSize(pageSize) {
            this.searchModel.PageSize = pageSize;
            this.getPageData();
        },
        //获取this.datas: {},//table数据对象
        getPageData() {
            var self = this;
            self.$http.post('Logs/PostPageList', this.searchModel).then(function (res) {
                if (res.data.status === 1) {
                    self.datas = res.data;
                }
                else {
                    self.$Modal.error({ title: '提示信息', content: res.data.message });
                }
            });
        },
        //编辑获取对象传入id
        editInfo(id) {//编辑
            var self = this;
            this.$http.get("Logs", { params: { id: id } }).then(//获取数据编辑项的值
                function (res) {
                    if (res.data.status == 1) {
                        self.dataModel = res.data.model;
                        self.modalShow();//打开modal
                    }
                    else {
                        self.$Modal.error({ title: "提示信息", content: "编辑数据加载失败!!!" });
                    }
                }
            );
        },
        //删除对象
        delInfo(id) {
            var self = this;
            self.$Modal.confirm({
                title: '提示信息',
                content: '<p>数据删除后不可恢复，确定要删除？</p>',
                onOk: () => {
                    this.$http.delete("Logs", { params: { id: id } }).then(
                        function (res) {
                            if (res.data.status == 1) {
                                self.$Notice.success({ title: '删除成功！', desc: false });
                                self.getPageData();
                            }
                            else {
                                self.$Modal.error({ title: "提示信息", content: "数据删除失败!!!" });
                            }
                        }
                    );
                }
            });
        },
        //保存方法
        save(modelname) {
            var self = this;
            this.$refs[modelname].validate((valid) => {
                if (valid) {
                    if (this.dataModel.Id === 0) {
                        this.$http.post('Logs', this.dataModel).then(
                            function (res) {
                                if (res.data.status == 1) {
                                    self.getPageData();//读取分页数据
                                    self.restModel(modelname);//重置model
                                    self.modalHide();//关闭modal
                                    self.$Notice.success({ title: '保存成功！', desc: false });
                                }
                                else {
                                    self.$Modal.warning({ title: "提示信息", content: "添加失败,请与管理员联系!" });
                                }
                            });
                    } else {
                        this.$http.put('Logs', this.dataModel).then(
                            function (res) {
                                if (res.data.status == 1) {
                                    self.getPageData();//读取分页数据
                                    self.restModel(modelname);//重置model
                                    self.modalHide();//关闭modal
                                    self.$Notice.success({ title: '更新成功！', desc: false });
                                }
                                else {
                                    self.$Modal.warning({ title: "提示信息", content: "更新失败,请与管理员联系!" });
                                }
                            });
                    }
                }
            });
        },
        //编辑框打开
        modalShow() {
            this.showType = true;
        },
        //编辑框关闭
        modalHide() {
            this.showType = false;
        },
        //取消方法
        cancel(modelname) {
            this.$refs[modelname].resetFields();//重置model
            this.showType = false;//关闭modal
        },
        //重置model
        restModel(modelname) {
            this.$refs[modelname].resetFields();//重置model
        },
        //全选方法
        selectAll(selection) {
            this.dataIds = selection;
        },
        //checkbox选中方法
        selectSingel(selection, row) {
            this.dataIds = selection;
        },
        //checkbox取消选中方法
        selecChange(selection) {
            this.dataIds = selection;
        },
        //批量删除
        multiSelect() {
            var self = this;
            if (this.dataIds.length !== 0) {
                self.$Modal.confirm({
                    title: '提示信息',
                    content: '<p>数据删除后不可恢复，确定要删除？</p>',
                    onOk: () => {
                        var ids = this.getDataIds(this.dataIds);
                        this.$http.post("Logs/PostBatchDelete", ids).then(
                            function (res) {
                                if (res.data.status == 1) {
                                    self.dataIds = [];
                                    self.$Notice.success({ title: '删除成功！', desc: false });
                                    self.getPageData();
                                }
                                else {
                                    self.$Modal.error({ title: "提示信息", content: "数据删除失败!!!" });
                                }
                            }
                        );
                    }
                });
            } else {
                self.$Modal.warning({ title: "提示信息", content: "请选择需要删除的数据!" });
            }

        },
        getDataIds(idList) {
            var ids = [];
            if (idList.length !== 0) {
                for (var i = 0; i < idList.length; i++) {
                    ids.push(idList[i].Id);
                }
            }
            return ids;
        }
    },
    //创建Vue页面方法
    created: function () {
        //创业Vue前调用获取this.datas: {},//table数据对象
        this.getPageData();
    },
    watch: {
        //需要监听的在此处新增监听对象
    }
}
</script>
